const arr = [10, 9, 8, 7, 6, 5, 5, 4, 3, 2, 1];

function quickSort(arr) {
    if (arr.length <= 1) return arr
    const pivotIndex = Math.floor(Math.random() * arr.length)
    const left = []
    const right = []
    const middle = []
    for (const item of arr) {
        if (item < arr[pivotIndex]) {
            left.push(item)
        } else if (item > arr[pivotIndex]) {
            right.push(item)
        } else {
            middle.push(item)
        }
    }
    return [...quickSort(left), ...middle, ...quickSort(right)]
}

console.log(quickSort(arr))